import { acceptHMRUpdate, defineStore } from 'pinia'
import { ref } from 'vue'
import { authFlagFromat } from '/@/utils/taskFormat'
import { listDataCompleted } from '/@/views/Task/ts/task'
export const workbenchesStrore = defineStore('weorkebenchesList', () => {
    const checkedId = ref("2")  //筛i选状态
    const completedStatusList = ref([])  //请求到的所有已完成数据
    const fillCompletedStatuslist = ref<listDataCompleted[]>([
        {
            applyManId: " ",
            applyManType: " ",
            createTime: " ",
            delFlag: " ",
            deptCode: " ",
            monManCredNum: " ",
            monManCredType: " ",
            monManName: " ",
            qrCodeUrl: " ",
            reportParam: " ",
            reportType: " ",
            reportValidTerm: " ",
            sex: " ",
            shortLink: " ",
            taskCode: " ",
            taskId: " ",
            taskStatus: " ",
            tunnelCode: " ",
            detailedAuthFlag: "",
            simpleAuthFlag: "",
            remark: ""
        }
    ]) //满足筛选条件的数据
    const setCheckId = (id: any) => {
        checkedId.value = id
    }
    const setCompletedStatusData = (data: any) => {
        completedStatusList.value = data
    }
    const filterCompletedData = () => {
        fillCompletedStatuslist.value = []
        if (checkedId.value == '2') {
            fillCompletedStatuslist.value = JSON.parse(JSON.stringify(completedStatusList.value))
        } else if (checkedId.value == '1') {
            let newArray = ref([])
            JSON.parse(JSON.stringify(completedStatusList.value))?.forEach((item: any) => {
                if (authFlagFromat(item) == '已授权') {
                    newArray.value.push(item)
                }
            });
            fillCompletedStatuslist.value = newArray.value
        } else if (checkedId.value == '0') {
            let newArray = ref([])
            JSON.parse(JSON.stringify(completedStatusList.value))?.forEach((item: any) => {
                if (authFlagFromat(item) == '未授权') {
                    newArray.value.push(item)
                }
            });
            fillCompletedStatuslist.value = newArray.value
        } else {
            // console.log("其他状态");
        }
    }
    return { checkedId, completedStatusList, fillCompletedStatuslist, setCheckId, setCompletedStatusData, filterCompletedData }
}, {
    persist: true
})

if (import.meta.hot) {
    import.meta.hot.accept(acceptHMRUpdate(workbenchesStrore, import.meta.hot))
}  
